///////////////////////////////////////////////////////////////////////
//  CS 3715 (Winter 2012), Final Project                      		 //
//  Program File Name: Server.java		                           	 //
//       Student Name: Jonathan Hart-Wall, Kenny Hardiman            //
//         Login Name: jcwhw1, kch004                                //
//              MUN #: 200933455, 200930253    						 //
///////////////////////////////////////////////////////////////////////
package ca.FMP;

import java.util.*;
import java.io.*;

/*
 * Database class
 */
public class Database {

	/**
	 * Creats ArrayList<PizzaPlace> db
	 */
	public ArrayList<PizzaPlace> db = new ArrayList<PizzaPlace>();

	/*
	 * Database method
	 */
	public Database() {
		try {

			/*
			 * Creates file reader to read in external text file line by line.
			 */
			FileInputStream read = new FileInputStream("PPDB.txt");
			DataInputStream reader = new DataInputStream(read);
			BufferedReader br = new BufferedReader(
					new InputStreamReader(reader));
			String line;

			while ((line = br.readLine()) != null) {

				/*
				 * Splits line by #, then creates PizzaPlace object a with all
				 * elements of pp
				 */
				String[] pp = line.split("#");

				String name = pp[0];
				String address = pp[1];
				String aot = pp[2];
				String pNum = pp[3];
				String storeHours = pp[4];

				PizzaPlace a = new PizzaPlace(name, address, aot, pNum,
						storeHours);

				a.setSmallPrice(Double.parseDouble(pp[5]));
				a.setMedPrice(Double.parseDouble(pp[6]));
				a.setLargePrice(Double.parseDouble(pp[7]));
				a.setXLargePrice(Double.parseDouble(pp[8]));
				a.setPartyPrice(Double.parseDouble(pp[9]));
				a.setImageLink(pp[10]);
				a.setToppingPrice(Double.parseDouble(pp[11]));

				/*
				 * Add a to Database
				 */
				db.add(a);
			}
		}

		/*
		 * Catch I/O Exception
		 */
		catch (IOException e) {
		}
	}
}